/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb;

import entities.Product;
import entities.TiendaliaOrder;
import entities.User;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Jesus
 */
@Stateless
public class TiendaliaOrderBean implements TiendaliaOrderBeanLocal {

    @PersistenceContext(unitName = "Tiendalia-ejbPU")
    private EntityManager em;

    @Override
    public TiendaliaOrder insert(TiendaliaOrder order) {
        return update(order);
    }

    @Override
    public TiendaliaOrder update(TiendaliaOrder order) {
        return em.merge(order);
    }

    @Override
    public List<TiendaliaOrder> findAll() {
        Query query = em.createNamedQuery("TiendaliaOrder.findAll");
        return query.getResultList();
    }

    @Override
    public List<TiendaliaOrder> findByCustomer(User user) {
        Query query = em.createNamedQuery("TiendaliaOrder.findByUser");
        query.setParameter("customer", user);
        return query.getResultList();
    }

    @Override
    public List<TiendaliaOrder> findByProduct(Product product) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
